﻿namespace O1.Kernel.IO.Storage
{
    internal class EdgeStore : AbstractFixedStore<Edge>
    {
        private VertexStore vertexStore;

        public EdgeStore(VertexStore vertexStore, BlockArray<byte[]> edgeStorage, int maxValue, int[] deleted)
            : base(edgeStorage, maxValue, deleted)
        {
            this.vertexStore = vertexStore;
        }

        public VertexStore Vertexes 
        {
            get
            { 
                return this.vertexStore; 
            }
        }

        protected override int RecordSize
        {
            get { return Edge.Size; }
        }

        protected override void WriteItem(Edge item, byte[] buffer, int offset)
        {
            item.Write(buffer, offset);
        }

        protected override Edge ReadItem(byte[] buffer, int recordOffset)
        {
            // TODO: Reduce garbage here using thread static singletons.
            return Edge.Read(buffer, recordOffset);
        }
    }
}
